// index.js文件
const app = getApp()	
Component({
  data: {
    show:false,
    active: 0,
    qrurl:'',
    list: [
      {
        "url": "/pages/home/home",
        "icon": "wap-home-o",
        "text": "首页"
      },
      {
        "url": "/pages/shop/shop",
        "icon": "shop-o",
        "text": "商场"
      },
      {
        "url": "/pages/order/order",
        "icon": "balance-list-o",
        "text": "订单"
      },
      {
        "url": "/pages/user/user",
        "icon": "user-circle-o",
        "text": "我的"
      }
    ]
    },
    methods: {
      
  showPopup() {
    this.setData({ show: true });
  },

  onClose() {
    this.setData({ show: false });
  },
     onChange(e) {
        console.log(e,'e')
        wx.switchTab({
          url: this.data.list[e.detail].url
        });
        this.setData({ active: e.detail });
     },
     
     init() {
         const page = getCurrentPages().pop();
         this.setData({
        　  active: this.data.list.findIndex(item => item.url === `/${page.route}`)
         });
        },
        //扫码
        scan(){
          var uuid= app.getuuid(40,16);
          // console.log(uuid);
          var openid;
          wx.getStorage({
            key: 'openid',
            success(res){
              openid=res.data;
            }
          })

          wx.scanCode({
            
            onlyFromCamera: false,
          success:(res)=>{
           // console.log(res);
          //  console.log(res);
          var that =this;     
            // console.log(this);
           const shopurl=res.result;
            console.log(shopurl);
             console.log("可获取的数据here");
               console.log("openid:");console.log(openid);
               console.log("uuid:");console.log(uuid);      
            if(uuid&&openid){
              console.log("openid:");console.log(openid);
               console.log("uuid:");console.log(uuid);   
            wx.request({
              url: shopurl,
              data:{
                openId:openid,
                uuid:uuid,
              },
              header: {
                'content-type': 'application/json' 
              },
              method:'GET',
              success:(res)=>{
                console.log(res);
                console.log
                // var that=this;
                wx.request({
                  url: 'http://47.115.152.5:8080/iot/listen_pay.do',
                  timeout: 120000,
                  data:{
                    openId:openid,
                    uuid:uuid,
                  },
                  method:"GET",
                  success: res=>{
                    console.log(res);
                    console.log("成功");
                    var t=res.data.data.qrUrl
                    that.setData({ 
                      show: true 
                    });    
                    that.setData({ 
                      qrurl:t  
                    });                
                    console.log(res);
                  },
                  fail: res=>{
                    console.log("失败")
                    console.log(res);
                  }
                })
                
              },
              fail(res){
                console.log(res);
              }
            })
          }
          else console.log("参数有误")
          }
          })
        
        }
     }
});